package org.convallaria.infrastruct.rg.example;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 示例Feign客户端降级处理
 * 当服务调用失败时提供降级响应
 * 
 * @author gjh
 * @since 2025-01-27
 */
@Slf4j
@Component
public class ExampleFeignClientFallback implements ExampleFeignClient {
    
    @Override
    public Map<String, Object> getSystemInfo() {
        log.warn("获取系统信息失败，使用降级响应");
        Map<String, Object> result = new HashMap<>();
        result.put("status", "fallback");
        result.put("message", "服务暂时不可用");
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
    
    @Override
    public Map<String, Object> getUserInfo(String userId) {
        log.warn("获取用户信息失败，使用降级响应: userId={}", userId);
        Map<String, Object> result = new HashMap<>();
        result.put("userId", userId);
        result.put("status", "fallback");
        result.put("message", "用户服务暂时不可用");
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
    
    @Override
    public Map<String, Object> healthCheck() {
        log.warn("健康检查失败，使用降级响应");
        Map<String, Object> result = new HashMap<>();
        result.put("status", "DOWN");
        result.put("message", "服务健康检查失败");
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
    
    @Override
    public Map<String, Object> getServiceStatus(String serviceName) {
        log.warn("获取服务状态失败，使用降级响应: serviceName={}", serviceName);
        Map<String, Object> result = new HashMap<>();
        result.put("serviceName", serviceName);
        result.put("status", "UNKNOWN");
        result.put("message", "服务状态查询失败");
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
}
